package com.dongdongshop.front.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.front.pojo.TbUser;
import com.dongdongshop.front.service.UserService;
import com.dongdongshop_util.JavaMailUtil;
import com.dongdongshop_util.SendComplexJavaMailUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class MailAndQuartz {

    @Reference(check = false,timeout = 50000)
    private UserService userService;

    //定时发邮件
    @Scheduled(cron = "0/10 * * * * ?")
    public void RegularMail() throws Exception {
        List<TbUser> list = userService.getAll();
        if(list != null && list.size() > 0){
            for (TbUser user : list) {

                Date userCreated = user.getCreated();
                Date newTime = new Date();
                Long time = (newTime.getTime() - userCreated.getTime())/1000/60/60/24;
                if(time == 30){
                    //主题
                   String title = "一封东东商城的感谢信";
                    //内容
                    String text = "感谢您对东东商城的信任，来个好评吧";
                    JavaMailUtil.useTencent(user.getEmail(),title,text);
                }
            }
        }
    }
}
